export const userNameAction = payload => ({ type: "changeUserName", payload });

// 异步action研究
// 2.1 store会自动回调这个函数，到时候再真正传入dispatch
export const unreadCountActionThunk = (setLoadingFunc) => {
    return dispatch => {
        setTimeout(() => {
            setLoadingFunc();
            const unReadCount = Math.floor(Math.random() * 20);
            // 数据请求是异步的，所以return并没有效果
            dispatch({ type: 'getUnreadCount', payload: unReadCount });
        }, 2000);
    }
};

// 2.2 返回一个promise是否更贴近实际网络请求常见
export const unreadCountActionPromise = (setLoadingFunc) => {
    return new Promise(resolve => {
        setTimeout(() => {
            setLoadingFunc();
            const unReadCount = Math.floor(Math.random() * 20);
            // 数据请求是异步的，所以return并没有效果
            resolve({ type: 'getUnreadCount', payload: unReadCount });
        }, 2000);
    })
}

